﻿/*
Copyright (c) 2010 Wolfgang Bruessler

http://code.google.com/p/sporttracks-csv-export/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZoneFiveSoftware.Common.Data;
using ZoneFiveSoftware.Common.Data.Fitness;
using ZoneFiveSoftware.Common.Data.GPS;
using ZoneFiveSoftware.Common.Visuals;
using ZoneFiveSoftware.Common.Data.Measurement;
using ZoneFiveSoftware.Common.Visuals.Fitness;

namespace SportTracksCsvExporter
{
    public partial class EditProfileForm : Form
    {
        public Setting s;

        public EditProfileForm()
        {
            InitializeComponent();
            s = null;
        }

        private void EditProfileForm_Load(object sender, EventArgs e)
        {
            textBoxProfileName.Text = s.profileName;
            delimeter.Text=s.delimeter;

            if (s.decimalSeparator != "")
            {
                decimalSeparator.Text = s.decimalSeparator;
            }
            else
            {
                decimalSeparator.SelectedIndex = 0;
            }
            if (s.culture != "")
            {
                culture.Text = s.culture;
            }
            else
            {
                culture.SelectedIndex = 0;
            }
            if (s.datetimeformat != "")
            {
                comboBoxDateTimeFormat.Text = s.datetimeformat;
            }
            else
            {
                comboBoxDateTimeFormat.SelectedIndex = 0;
            }
            if (s.dateformat != "")
            {
                comboBoxDateFormat.Text = s.dateformat;
            }
            else
            {
                comboBoxDateFormat.SelectedIndex = 0;
            }
            if (s.timeformat != "")
            {
                comboBoxTimeFormat.Text = s.timeformat;
            }
            else
            {
                comboBoxTimeFormat.SelectedIndex = 0;
            }
            exportSmoothedData.Checked = s.exportSmoothedData;

            comboBoxDistanceUnit.Text = s.distanceUnit;
            comboBoxElevationUnit.Text = s.elevationUnit;
            comboBoxSpeedUnit.Text = s.speedUnit;
            comboBoxCaloriesUnit.Text = s.caloriesUnit;
            comboBoxTemperatureUnit.Text = s.temperatureUnit;
            comboBoxWeightUnit.Text = s.weightUnit;
            unitsBehindValues.Checked = s.unitsBehindValues;
            unitsBehindTokens.Checked = s.unitsBehindTokens;
            comboBoxFileNameFormat.Text = s.customExportFilename;

            exportDateTime.Checked = s.exportDateTime;
            exportDate.Checked = s.exportDate;
            exportTime.Checked = s.exportTime;
            datetimeToken.Text = s.datetimeToken;
            dateToken.Text = s.dateToken;
            timeToken.Text = s.timeToken;
            exportCategory.Checked = s.exportCategory;
            categoryToken.Text = s.categoryToken;
            exportSubcategory.Checked = s.exportSubCategory;
            subcategoryToken.Text = s.subcategoryToken;
            exportLocation.Checked = s.exportLocation;
            locationToken.Text = s.locationToken;
            exportName.Checked = s.exportName;
            nameToken.Text = s.nameToken;
            exportDistance.Checked = s.exportDistance;
            distanceToken.Text = s.distanceToken;
            exportElevation.Checked = s.exportElevation;
            elevationToken.Text = s.elevationToken;
            exportGrade.Checked = s.exportGrade;
            gradeToken.Text = s.gradeToken;
            exportTotalAscended.Checked = s.exportTotalAscended;
            totalascendToken.Text = s.totalascendToken;
            exportTotalDescended.Checked = s.exportTotalDescended;
            totaldescendToken.Text = s.totaldescendToken;
            exportDuration.Checked = s.exportDuration;
            durationToken.Text = s.durationToken;
            exportPausedTime.Checked = s.exportPausedTime;
            pausedtimeToken.Text = s.pausedtimeToken;

            exportSpeed.Checked = s.exportSpeed;
            speedToken.Text = s.speedToken;
            exportAverageSpeed.Checked = s.exportAverageSpeed;
            averagespeedToken.Text = s.averagespeedToken;
            exportMaxSpeed.Checked = s.exportMaxSpeed;
            maxSpeedToken.Text = s.maxspeedToken;
            exportCalories.Checked = s.exportCalories;
            caloriesToken.Text = s.caloriesToken;
            exportHeartrate.Checked = s.exportHeartrate;
            heartrateToken.Text = s.heartrateToken;
            exportAverageHeartrate.Checked = s.exportAverageHeartrate;
            averageheartrateToken.Text = s.averageheartrateToken;
            exportMaxHeartrate.Checked = s.exportMaxHeartrate;
            maxheartrateToken.Text = s.maxheartrateToken;
            exportIntensity.Checked = s.exportIntensity;
            intensityToken.Text = s.intensityToken;
            exportCadence.Checked = s.exportCadence;
            cadenceToken.Text = s.cadenceToken;
            exportAverageCadence.Checked = s.exportAverageCadence;
            averagecadenceToken.Text = s.averagecadenceToken;
            exportMaxCadence.Checked = s.exportMaxCadence;
            maxcadenceToken.Text = s.maxcadenceToken;
            exportPower.Checked = s.exportPower;
            powerToken.Text = s.powerToken;
            exportAveragePower.Checked = s.exportAveragePower;
            averagepowerToken.Text = s.averagepowerToken;
            exportMaxPower.Checked = s.exportMaxPower;
            maxpowerToken.Text = s.maxpowerToken;

            exportTemperature.Checked = s.exportTemperature;
            temperatureToken.Text = s.temperatureToken;
            exportWeather.Checked = s.exportWeather;
            weatherToken.Text = s.weatherToken;
            exportEquipment.Checked = s.exportEquipment;
            equipmentToken.Text = s.equipmentToken;
            exportNotes.Checked = s.exportNotes;
            notesToken.Text = s.notesToken;
            exportZones.Checked = s.exportZones;
            zonetypeToken.Text = s.zonetypeToken;
            zonecategoryToken.Text = s.zonecategoryToken;
            zonenameToken.Text = s.zonenameToken;
            zonepercentToken.Text = s.zonepercentToken;
            exportRecordedLaps.Checked = s.exportRecordedLaps;
            exportCustomLaps.Checked = s.exportCustomLaps;
            exportRegularDistanceLaps.Checked = s.exportRegularDistanceLaps;
            laptypeToken.Text = s.laptypeToken;
            lapToken.Text = s.lapToken;
            regularDistance.Text = s.regularLapDistanceMeters.ToString();
            exportGps.Checked = s.exportGps;
            latToken.Text = s.latToken;
            lonToken.Text = s.lonToken;

            exportWeight.Checked = s.exportWeight;
            weightToken.Text = s.weightToken;
            exportBodyFat.Checked = s.exportBodyFat;
            bodyfatToken.Text = s.bodyfatToken;
            exportBmi.Checked = s.exportBmi;
            bmiToken.Text = s.bmiToken;
            exportSkinfold.Checked = s.exportSkinfold;
            skinfoldToken.Text = s.skinfoldToken;
            exportRestHeartrate.Checked = s.exportAthleteRestingHr;
            restheartrateToken.Text = s.athleterestinghrToken;
            exportAthleteMaxHeartrate.Checked = s.exportAthleteMaxHr;
            athletemaxheartrateToken.Text = s.athletemaxhrToken;
            exportSystolic.Checked = s.exportSystolic;
            systolicToken.Text = s.systolicToken;
            exportDiastolic.Checked = s.exportDiastolic;
            diastolicToken.Text = s.diastolicToken;
            exportCaloriesConsumed.Checked = s.exportCaloriesConsumed;
            caloriesconsumedToken.Text = s.caloriesconsumedToken;
            exportMood.Checked = s.exportMood;
            moodToken.Text = s.moodToken;

            exportSleep.Checked = s.exportSleep;
            sleepToken.Text = s.sleepToken;
            exportSleepQuality.Checked = s.exportSleepQuality;
            sleepqualityToken.Text = s.sleepqualityToken;
            exportInjured.Checked = s.exportInjured;
            injuredToken.Text = s.injuredToken;
            injurednotesToken.Text = s.injuredTextToken;
            exportSick.Checked = s.exportSick;
            sickToken.Text = s.sickToken;
            sicknotesToken.Text = s.sickTextToken;
            exportMissedWorkout.Checked = s.exportMissedWorkout;
            missedworkoutToken.Text = s.exportmissedworkoutToken;
            missedworkoutnotesToken.Text = s.exportmissedworkoutTextToken;
            exportDiary.Checked = s.exportDiary;
            diaryToken.Text = s.diaryToken;
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            s.profileName = textBoxProfileName.Text;
            s.delimeter = delimeter.Text;
            if (decimalSeparator.SelectedIndex == 0)
            {
                s.decimalSeparator = "";
            }
            else
            {
                s.decimalSeparator = decimalSeparator.Text;
            }
            if (culture.SelectedIndex == 0)
            {
                s.culture="";
            }
            else
            {
                s.culture = culture.Text;
            }
            if (comboBoxDateTimeFormat.SelectedIndex == 0)
            {
                s.datetimeformat = "";
            }
            else
            {
                s.datetimeformat = comboBoxDateTimeFormat.Text;
            }
            if (comboBoxDateFormat.SelectedIndex == 0)
            {
                s.dateformat = "";
            }
            else
            {
                s.dateformat = comboBoxDateFormat.Text;
            }
            if (comboBoxTimeFormat.SelectedIndex == 0)
            {
                s.timeformat = "";
            }
            else
            {
                s.timeformat = comboBoxTimeFormat.Text;
            }
            s.exportSmoothedData = exportSmoothedData.Checked;
            s.customExportFilename = comboBoxFileNameFormat.Text;

            s.distanceUnit = comboBoxDistanceUnit.Text;
            s.elevationUnit=comboBoxElevationUnit.Text;
            s.speedUnit=comboBoxSpeedUnit.Text;
            s.caloriesUnit=comboBoxCaloriesUnit.Text;
            s.temperatureUnit=comboBoxTemperatureUnit.Text;
            s.weightUnit=comboBoxWeightUnit.Text;
            s.unitsBehindValues = unitsBehindValues.Checked;
            s.unitsBehindTokens = unitsBehindTokens.Checked;

            s.exportDateTime=exportDateTime.Checked;
            s.exportDate=exportDate.Checked;
            s.exportTime=exportTime.Checked;
            s.datetimeToken=datetimeToken.Text;
            s.dateToken=dateToken.Text;
            s.timeToken=timeToken.Text;
            s.exportCategory=exportCategory.Checked;
            s.categoryToken=categoryToken.Text;
            s.exportSubCategory=exportSubcategory.Checked;
            s.subcategoryToken=subcategoryToken.Text;
            s.exportLocation=exportLocation.Checked;
            s.locationToken=locationToken.Text;
            s.exportName=exportName.Checked;
            s.nameToken=nameToken.Text;
            s.exportDistance = exportDistance.Checked;
            s.distanceToken = distanceToken.Text;
            s.exportElevation=exportElevation.Checked;
            s.elevationToken=elevationToken.Text;
            s.exportGrade=exportGrade.Checked;
            s.gradeToken=gradeToken.Text;
            s.exportTotalAscended=exportTotalAscended.Checked;
            s.totalascendToken=totalascendToken.Text;
            s.exportTotalDescended=exportTotalDescended.Checked;
            s.totaldescendToken=totaldescendToken.Text;
            s.exportDuration=exportDuration.Checked;
            s.durationToken=durationToken.Text;
            s.exportPausedTime=exportPausedTime.Checked;
            s.pausedtimeToken=pausedtimeToken.Text;

            s.exportSpeed=exportSpeed.Checked;
            s.speedToken=speedToken.Text;
            s.exportAverageSpeed=exportAverageSpeed.Checked;
            s.averagespeedToken=averagespeedToken.Text;
            s.exportMaxSpeed=exportMaxSpeed.Checked;
            s.maxspeedToken=maxSpeedToken.Text;
            s.exportCalories=exportCalories.Checked;
            s.caloriesToken=caloriesToken.Text;
            s.exportHeartrate=exportHeartrate.Checked;
            s.heartrateToken=heartrateToken.Text;
            s.exportAverageHeartrate=exportAverageHeartrate.Checked;
            s.averageheartrateToken=averageheartrateToken.Text;
            s.exportMaxHeartrate=exportMaxHeartrate.Checked;
            s.maxheartrateToken=maxheartrateToken.Text;
            s.exportIntensity=exportIntensity.Checked;
            s.intensityToken=intensityToken.Text;
            s.exportCadence=exportCadence.Checked;
            s.cadenceToken=cadenceToken.Text;
            s.exportAverageCadence=exportAverageCadence.Checked;
            s.averagecadenceToken=averagecadenceToken.Text;
            s.exportMaxCadence=exportMaxCadence.Checked;
            s.maxcadenceToken=maxcadenceToken.Text;
            s.exportPower=exportPower.Checked;
            s.powerToken=powerToken.Text;
            s.exportAveragePower=exportAveragePower.Checked;
            s.averagepowerToken=averagepowerToken.Text;
            s.exportMaxPower=exportMaxPower.Checked;
            s.maxpowerToken=maxpowerToken.Text;

            s.exportTemperature=exportTemperature.Checked;
            s.temperatureToken=temperatureToken.Text;
            s.exportWeather=exportWeather.Checked;
            s.weatherToken=weatherToken.Text;
            s.exportEquipment=exportEquipment.Checked;
            s.equipmentToken=equipmentToken.Text;
            s.exportNotes=exportNotes.Checked;
            s.notesToken=notesToken.Text;
            s.exportZones=exportZones.Checked;
            s.zonetypeToken=zonetypeToken.Text;
            s.zonecategoryToken=zonecategoryToken.Text;
            s.zonenameToken=zonenameToken.Text;
            s.zonepercentToken=zonepercentToken.Text;
            s.exportRecordedLaps=exportRecordedLaps.Checked;
            s.exportCustomLaps=exportCustomLaps.Checked;
            s.exportRegularDistanceLaps=exportRegularDistanceLaps.Checked;
            s.laptypeToken=laptypeToken.Text;
            s.lapToken=lapToken.Text;
            try
            {
                s.regularLapDistanceMeters = System.Convert.ToDouble(regularDistance.Text);
            }
            catch (Exception)
            {
            }
            s.exportGps=exportGps.Checked;
            s.latToken=latToken.Text;
            s.lonToken=lonToken.Text;

            s.exportWeight=exportWeight.Checked;
            s.weightToken=weightToken.Text;
            s.exportBodyFat=exportBodyFat.Checked;
            s.bodyfatToken=bodyfatToken.Text;
            s.exportBmi=exportBmi.Checked;
            s.bmiToken=bmiToken.Text;
            s.exportSkinfold=exportSkinfold.Checked;
            s.skinfoldToken=skinfoldToken.Text;
            s.exportAthleteRestingHr=exportRestHeartrate.Checked;
            s.athleterestinghrToken=restheartrateToken.Text;
            s.exportAthleteMaxHr=exportAthleteMaxHeartrate.Checked;
            s.athletemaxhrToken=athletemaxheartrateToken.Text;
            s.exportSystolic=exportSystolic.Checked;
            s.systolicToken=systolicToken.Text;
            s.exportDiastolic=exportDiastolic.Checked;
            s.diastolicToken=diastolicToken.Text;
            s.exportCaloriesConsumed=exportCaloriesConsumed.Checked;
            s.caloriesconsumedToken=caloriesconsumedToken.Text;
            s.exportMood=exportMood.Checked;
            s.moodToken=moodToken.Text;

            s.exportSleep=exportSleep.Checked;
            s.sleepToken=sleepToken.Text;
            s.exportSleepQuality=exportSleepQuality.Checked;
            s.sleepqualityToken=sleepqualityToken.Text;
            s.exportInjured=exportInjured.Checked;
            s.injuredToken=injuredToken.Text;
            s.injuredTextToken=injurednotesToken.Text;
            s.exportSick=exportSick.Checked;
            s.sickToken=sickToken.Text;
            s.sickTextToken=sicknotesToken.Text;
            s.exportMissedWorkout=exportMissedWorkout.Checked;
            s.exportmissedworkoutToken=missedworkoutToken.Text;
            s.exportmissedworkoutTextToken=missedworkoutnotesToken.Text;
            s.exportDiary=exportDiary.Checked;
            s.diaryToken=diaryToken.Text;
        }

        private void linkLabelDateTimeFormatHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                linkLabelDateTimeFormatHelp.LinkVisited = true;
                System.Diagnostics.Process.Start("http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
